package com.mms.service;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import org.junit.Test;

import com.mms.entity.User;
import com.mms.entity.UserRole;

/**
 * UserServiceImpl的单元测试类
 * @author Administrator
 *
 */
public class UserServiceImplTest {

	UserServiceImpl svc = new UserServiceImpl();
	
	@Test
	public void testLogin() {
		User user = this.svc.login("zima", "kaimen");
		System.out.println(user);
	}

	@Test
	public void testLogout() {
		fail("Not yet implemented");
	}

	@Test
	public void testCreateUser() {
		// 模拟帐号管理员在界面上创建新用户时填写的信息
		User newUser = new User();
		newUser.setUsername("zima");
		newUser.setManager("leo");
		newUser.setRole(UserRole.NORMAL);
		// 调用要测试的目标方法
		this.svc.createUser(newUser);
	}

	@Test
	public void testDisableUser() {
		this.svc.disableUser("zima");
	}

	@Test
	public void testEnableUser() {
		this.svc.enableUser("zima");
	}

	@Test
	public void testUpdatePassword1() {
		boolean ret = this.svc.updatePassword("zima", "123456", "kaimen");
		assertTrue(ret);
	}
	
	@Test
	public void testUpdatePassword2() {
		boolean ret = this.svc.updatePassword("zima", "ohwitgdosdogsaewirhosalzbfsirw", "kaimen");
		assertFalse(ret);
	}

}
